Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --remote flag for remote connection #10352

Merged
merged 21 commits into from
Mar 7, 2024
Merged

Add --remote flag for remote connection #10352

merged 21 commits into from
Mar 7, 2024

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Mar 6, 2024

Changes

Require the --remote flag to dev or build with a studio connection. Use a local db with local seeding for standard astro build call.

  • Add --remote check to dev and build
  • Add --remote support to shell and execute
  • Move table recreation from runtime to buildtime. Prevents build hanging failure and unblocks SSR app usage
  • Refactor in-memory databases to a generate db hash. Solves the clobbering problem and remove all special logic for in-memory data
  • Misc: remove bad author3 and author4 config in ticketing example

Testing

  • Add in-memory db patch for seeding to ensure tests still run

Docs

https://docs-git-sarah-patch-6-astrodotbuild.vercel.app/en/guides/astro-db/#production-builds

Copy link

changeset-bot bot commented Mar 6, 2024

🦋 Changeset detected

Latest commit: ff057e1

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@FredKSchott
Copy link
Member

FredKSchott commented Mar 7, 2024

LGTM! Can you add to other commands as well?

  • astro dev --remote
  • astro db shell --remote
  • astro db execute --remote

If local astro shell and local astro execute aren't actually a thing then it's okay to error if no --remote flag is found, asking you to add the --remote to remove the error.

astro db push and astro db verify I'm okay if no flag since they literally don't make sense unless they're in the remote context.

@bholmesdev bholmesdev changed the title Add build --remote flag for remote connection Add --remote flag for remote connection Mar 7, 2024
export const RUNTIME_CONFIG_IMPORT = JSON.stringify(`${PACKAGE_NAME}/runtime/config`);

export const DB_TYPES_FILE = 'db-types.d.ts';

export const VIRTUAL_MODULE_ID = 'astro:db';

export const DB_PATH = '.astro/content.db';
export const DB_PATH = `.astro/${
process.env.ASTRO_TEST_RANDOM_DB_ID ? randomUUID() : 'content.db'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this regenerated when some HMR change is triggered or when we restart the server? Is it fine if it is regenerated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be regenerated for our test runners! See comment on the basics test. In short, the test runner starts multiple dev servers in parallel if it finds this optimal (does not occur locally for some reason). If there's multiple servers pointing to the same db file, seed data will be clobbered. We also can't inject a db name as an environment variable because then the environment variable would get clobbered by each test run 😅 This is the best compromise I could find

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, if you're wondering if the ID is stable for the lifetime of the test, it seems to be. Can't think of an HMR trigger

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for the detailed explanation :) just making sure if that's what we need

packages/db/src/runtime/index.ts Outdated Show resolved Hide resolved
@bholmesdev
Copy link
Contributor Author

@FredKSchott done! Added the --remote treatment to dev, shell, and execute. Should make local and remote debugging much more powerful 👏

@bholmesdev bholmesdev merged commit 06fe94e into main Mar 7, 2024
13 checks passed
@bholmesdev bholmesdev deleted the feat/build-remote branch March 7, 2024 18:38
@astrobot-houston astrobot-houston mentioned this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants